package com.yunva.detectsandbox;


import com.yunva.Detect.JNIUtil;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

@SuppressLint("HandlerLeak") public class MainActivity extends Activity implements OnClickListener {

	private TextView tv_result;
	private Button bn_test;
	private boolean detectFlag = false;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
        Log.e("ABI", android.os.Build.CPU_ABI);
		InitView();

	}

	private void InitView() {
		// TODO Auto-generated method stub
		tv_result = (TextView) findViewById(R.id.tv_result);
		bn_test = (Button) findViewById(R.id.bn_test);
		bn_test.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bn_test:
			tv_result.setText("");
			Detect();
			break;
		}
	}

	private void Detect() {
		// TODO Auto-generated method stub
		new Thread()
		{
			public void run() {
				detectFlag = JNIUtil.Detect();
				m_hanler.sendEmptyMessage(1);
			}
		}.start();
	}

	public Handler m_hanler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 1:
				ShowResult();
				break;
			case 2:

				break;
			}
		};
	};

	protected void ShowResult() {
		// TODO Auto-generated method stub
		if(detectFlag)
		{
			tv_result.setText("根据特征值，检测到的设备是真机！");
		}
		else
			{
			tv_result.setText("根据特征值，检测到的设备是模拟器！");
			}
	}

}
